package com.zhy.generator.codegen.internal.tableattribute;

import com.zhy.generator.codegen.api.IntrospectedTable;
import com.zhy.generator.config.ConfigurationConstant;

public class JavaAttributes {
    private IntrospectedTable introspectedTable;
    public JavaAttributes(IntrospectedTable introspectedTable){
        this.introspectedTable = introspectedTable;
    }

    public void calculateModelAttributes() {

        String modelPackage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_PO);
        StringBuilder sb = new StringBuilder();
        sb.append(modelPackage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Key"); //$NON-NLS-1$
        setPrimaryKeyType(sb.toString());

        sb.setLength(0);
        sb.append(modelPackage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        setBaseRecordType(sb.toString());

        sb.setLength(0);
        sb.append(modelPackage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("WithBLOBs"); //$NON-NLS-1$
        setRecordWithBLOBsType(sb.toString());

        sb.setLength(0);
        sb.append(modelPackage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Example"); //$NON-NLS-1$
        setExampleType(sb.toString());
    }

    public void calculateVoAttributes() {
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_VO);
        StringBuilder sb = new StringBuilder();
        sb.append(pakkage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("VO"); //$NON-NLS-1$
        setVoType(sb.toString());
    }

    public void calculateServiceAttributes() {
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_SERVICE);
        StringBuilder sb = new StringBuilder();
        sb.append(pakkage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Service"); //$NON-NLS-1$
        setServiceType(sb.toString());
    }

    public void calculateMapperAttributes() {
        String mapperPackage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_MAPPER);
        StringBuilder sb = new StringBuilder();
        sb.append(mapperPackage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("DAO"); //$NON-NLS-1$
        setDAOImplementationType(sb.toString());

        sb.setLength(0);
        sb.append(mapperPackage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Mapper");
        setMyBatis3JavaMapperType(sb.toString());
    }

    public void calculateRequestAttributes() {
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_REQUEST);
        StringBuilder sb = new StringBuilder();
        sb.append(pakkage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Request"); //$NON-NLS-1$
        setRequestType(sb.toString());
    }

    public void calculateHelperAttributes() {
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_HELPER);
        StringBuilder sb = new StringBuilder();
        sb.append(pakkage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Helper"); //$NON-NLS-1$
        setHelperType(sb.toString());
    }

    public void calculateControllerAttributes() {
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_CONTROLLER);
        StringBuilder sb = new StringBuilder();
        sb.append(pakkage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Ct"); //$NON-NLS-1$
        setControllerType(sb.toString());
    }

    public void calculateConstantAttributes() {
        String pakkage = introspectedTable.calculateJavaPackage(ConfigurationConstant.CONFIGURATION_CONSTANT);
        StringBuilder sb = new StringBuilder();
        sb.append(pakkage);
        sb.append('.');
        sb.append(introspectedTable.getDomainObjectName());
        sb.append("Constant"); //$NON-NLS-1$
        setConstantType(sb.toString());
    }

    public void setPrimaryKeyType(String primaryKeyType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_PRIMARY_KEY_TYPE, primaryKeyType);
    }

    public void setBaseRecordType(String baseRecordType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_BASE_RECORD_TYPE, baseRecordType);
    }

    public void setRecordWithBLOBsType(String recordWithBLOBsType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_RECORD_WITH_BLOBS_TYPE, recordWithBLOBsType);
    }

    public void setExampleType(String exampleType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_EXAMPLE_TYPE, exampleType);
    }

    public void setServiceType(String serviceType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_SERVICE_TYPE, serviceType);
    }

    private void setVoType(String voType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_VO_TYPE, voType);
    }

    public void setDAOImplementationType(String daoImplementationType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_DAO_IMPLEMENTATION_TYPE, daoImplementationType);
    }

    public void setMyBatis3JavaMapperType(String mybatis3JavaMapperType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_MYBATIS3_JAVA_MAPPER_TYPE, mybatis3JavaMapperType);
    }

    public void setRequestType(String requestType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_REQUEST_TYPE, requestType);
    }

    public void setControllerType(String controllerType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_CONTROLLER_TYPE, controllerType);
    }

    public void setHelperType(String helperType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_HELPER_TYPE, helperType);
    }

    public void setConstantType(String helperType) {
        introspectedTable.setInternalAttributes(InternalAttribute.ATTR_CONSTANT_TYPE, helperType);
    }

}
